package com.calculator.pmzvfk;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import java.util.ArrayList;

public class HistoryDialogFragment extends DialogFragment {

    private ArrayList<String> history;

    public HistoryDialogFragment(ArrayList<String> history) {
        this.history = history;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_history, null);
        ListView listView = view.findViewById(R.id.historyListView);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, history);
        listView.setAdapter(adapter);
        dialog.setContentView(view);
        return dialog;
    }
}